import { createRouter, createWebHistory } from 'vue-router'
import Layout from '../components/Layout.vue'
// 路由
const routes=[
  {
    path: '/',
    name: 'Layout',
    component:Layout,
    redirect: "home", //重定向到home页面
    children:[
      {
        path:"home",
        name:"Home",
        component:()=>import("/src/views/Home.vue")
      },
      {
        path:"user",
        name:"User",
        component:()=>import("/src/views/User.vue")
      },
      {
        path:"role",
        name:"Role",
        component:()=>import("/src/views/Role.vue")
      },
      {
        path:"center",
        name:"Center",
        component:()=>import("/src/views/Center.vue")
      }
    ],
  },
  {
    path: '/login',
    name: "登录",
    component: ()=>import("/src/views/Login.vue")
  },
]

const router = createRouter({
  history: createWebHistory(),
  routes
});

export default router
// 判断登录
router.beforeEach((to, from, next) => {
  // // 判断用户是否登录
  // if (to.path !== '/login' && !sessionStorage.getItem('user')) {
  //   // 用户未登录，跳转到登录界面
  //   next('/login')
  // } else {
    next()
  // }
})